import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { File } from './entities/file.entity';
import { Repository } from 'typeorm';
@Injectable()
export class FileService {
  constructor(
    @InjectRepository(File)
    private readonly fileRepository: Repository<File>,
  ) {}
  setFinger(path, fingerPrint) {
    this.fileRepository.save({ path, fingerPrint });
  }

  async getFile(fingerPrint) {
    const result = await this.fileRepository.findOne({
      where: { fingerPrint: fingerPrint },
    });
    if (!result) {
      throw new NotFoundException('没有上传相应的文件');
    }
    return result;
  }
}
